package com.skit.main.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.skit.common.ResourcesManager
import com.skit.common.bean.ActivityBean
import com.skit.main.R
import kotlinx.android.synthetic.main.main_fragment_activity_type.*
import java.text.SimpleDateFormat
import java.util.*

/**
 * @author shuike <a href="mailto:shuike007@gmail.com">Contact me.</a>
 * @version 1.0
 * @since  2020/5/27
 */

class ActivityTypeInfoFragment : Fragment() {
    private val format = SimpleDateFormat("MM月dd日 HH:mm", Locale.getDefault())

    companion object {
        fun newInstances(activityBean: ActivityBean): ActivityTypeInfoFragment {
            val fragment: ActivityTypeInfoFragment = ActivityTypeInfoFragment()
            val bundle: Bundle = Bundle()
            bundle.putSerializable("bean", activityBean)

            fragment.arguments = bundle
            return fragment
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? = inflater.inflate(R.layout.main_fragment_activity_type, container, false)

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        val bean: ActivityBean = arguments?.getSerializable("bean") as ActivityBean
        activity_type.text =
            resources.getString(R.string.main_activity_type, bean.type?.name)

        val nd = 1000 * 24 * 60 * 60.toLong()
        val nh = 1000 * 60 * 60.toLong()

        val diff: Long = bean.endTime - bean.startTime

//        val hour: Int = (diff % nd / nh).toInt()

        val hour = (bean.endTime - bean.startTime) / (60 * 60 * 1000)

        activity_time.text = ResourcesManager.getRes().getString(
            R.string.activity_often, hour
        )

        activity_score.text = resources.getString(
            R.string.main_score_details, bean.adminScore, bean.adminScore, bean.stuScore
        )


    }
}